package com.yssw.customer.service.impl;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;

import com.yssw.common.utils.DateUtils;
import com.yssw.customer.domain.ServiceType;
import com.yssw.customer.service.IServiceTypeService;
import com.yssw.onlinechat.dto.SocketMsg;
import com.yssw.util.IdGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yssw.customer.mapper.CustomerTableMapper;
import com.yssw.customer.domain.CustomerTable;
import com.yssw.customer.service.ICustomerTableService;

/**
 * 客户申报管理Service业务层处理
 *
 * @author yssw
 * @date 2023-03-28
 */
@Slf4j
@Service
public class CustomerTableServiceImpl implements ICustomerTableService {
    @Autowired
    private CustomerTableMapper customerTableMapper;

    private static AtomicInteger msgNum=new AtomicInteger(0);


    /**
     * 查询客户申报管理
     *
     * @param id 客户申报管理主键
     * @return 客户申报管理
     */
    @Override
    public CustomerTable selectCustomerTableById(Long id) {
        return customerTableMapper.selectCustomerTableById(id);
    }

    /**
     * 查询客户申报管理列表
     *
     * @param customerTable 客户申报管理
     * @return 客户申报管理
     */
    @Override
    public List<CustomerTable> selectCustomerTableList(CustomerTable customerTable) {
        return customerTableMapper.selectCustomerTableList(customerTable);
    }

    /**
     * 新增客户申报管理
     *
     * @param customerTable 客户申报管理
     * @return 结果
     */
    @Override
    public int insertCustomerTable(CustomerTable customerTable) {
        msgNum.set(msgNum.get()+1);
        customerTable.setOrderNumber(String.valueOf(IdGenerator.generateId()));
        customerTable.setCreateTime(DateUtils.getNowDate());
        return customerTableMapper.insertCustomerTable(customerTable);
    }

    /**
     * 修改客户申报管理
     *
     * @param customerTable 客户申报管理
     * @return 结果
     */
    @Override
    public int updateCustomerTable(CustomerTable customerTable) {
        customerTable.setUpdateTime(DateUtils.getNowDate());
        return customerTableMapper.updateCustomerTable(customerTable);
    }

    /**
     * 批量删除客户申报管理
     *
     * @param ids 需要删除的客户申报管理主键
     * @return 结果
     */
    @Override
    public int deleteCustomerTableByIds(Long[] ids) {
        return customerTableMapper.deleteCustomerTableByIds(ids);
    }

    /**
     * 删除客户申报管理信息
     *
     * @param id 客户申报管理主键
     * @return 结果
     */
    @Override
    public int deleteCustomerTableById(Long id) {
        return customerTableMapper.deleteCustomerTableById(id);
    }

    @Override
    public SocketMsg getMsg() {
        SocketMsg socketMsg=new SocketMsg();
        socketMsg.setMsg("有新的客户发起报装或故障维修信息，当前未读数量为: "+msgNum.get());
        socketMsg.setParam(msgNum.get());
        return socketMsg;
    }

    @Override
    public SocketMsg clearMsg() {
        msgNum.set(0);
        SocketMsg socketMsg = new SocketMsg();
        socketMsg.setMsg("清空成功");
        return socketMsg;
    }
}
